<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :data="tableData"
        :permission="permissionList"
        :search.sync="searchForm"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="refreshChange"
        @on-load="refreshChange"
      >
        <template slot="menuLeft">
          <el-button type="primary" v-if="permissionList.delBtn" size="mini" @click="addReportData">加入报表差错</el-button>
	   <el-button
            type="primary"
            size="small"
            @click.stop="rejectBatch"
            v-permission="permissionList.delBtn"
            >驳回</el-button
          >
          <el-button type="primary" size="small" v-if="false" @click.stop="handleExport">导出</el-button>
          <el-button type="primary" size="small" :hidden="true" v-if="false" @click="handlePrint">打印</el-button>
          <addReportEditor ref="addReportEditor" @addReportSuccess="getList"></addReportEditor>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button
            icon="el-icon-check"
            :size="scope.size"
            :type="scope.type"
            v-if="scope.row.status=='1' && scope.row.auditStatus=='0'"
            v-permission="permissionList.auditBtn"
            @click.stop="myEdit(scope.row)"
          >审核</el-button>
          <el-button
            icon="el-icon-check"
            :size="scope.size"
            :type="scope.type"
            v-if="scope.row.auditStatus=='1'"
            v-permission="permissionList.auditBtn"
            @click.stop="myEdit(scope.row)"
          >撤回审核</el-button>
          <el-button
            icon="el-icon-view"
            :size="scope.size"
            :type="scope.type"
            @click.stop="myView(scope.row)"
          >预览</el-button>
          <el-button
            icon="el-icon-delete"
            :size="scope.size"
            :type="scope.type"
            v-permission="permissionList.superDelBtn"
            @click.stop="myDelete(scope.row)"
          >删除</el-button>
        </template>
      </avue-crud>

      <el-dialog
        width="70%"
        :visible.sync="editDialogVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :fullscreen="editchangeDialogFlag"
      >
        <div slot="title">
          <div>
            <span class="el-dialog__title">审核</span>
            <div class="avue-crud__dialog__menu">
              <button
                class="el-dialog__headerbtn"
                style="margin-right:20px"
                @click.stop="viewchangeDialog"
              >
                <i class="el-dialog__close el-icon-full-screen"></i>
              </button>
            </div>
            <button type="button" aria-label="Close" class="el-dialog__headerbtn">
              <i class="el-dialog__close el-icon el-icon-close"></i>
            </button>
          </div>
        </div>
        <el-form :model="formAdd">
          <div style="min-height: 36px;background: #99a9bf;line-height:36px;margin-top:4px;">单程票盘点</div>
          <table border="1" bordercolor="#EEEEEE" width="100%">
            <tr>
              <th>项目</th>
              <th>车站票务管理室原有单程票</th>
              <th>TVM票箱单程票</th>
              <th>BOM票箱单程票</th>
              <th>AGM票箱单程票</th>
              <th>STM票箱单程票</th>
              <th>TVM废票箱单程票</th>
              <th>BOM废票箱单程票</th>
              <th>AGM废票箱单程票</th>
              <th>STM废票箱单程票</th>
              <th>车票回收箱单程票</th>
              <th style="width: 70px;">合计</th>
            </tr>
            <tr style="display: none">
              <th>SC清点总数</th>

              <td
                v-for="(item,index) in formAdd.checkOneways"
                :key="index"
                style="text-align:center"
              >{{item.scCleanNumber}}</td>
            </tr>
            <tr>
              <th>实际盘点数量</th>
              <td
                v-for="(item,index) in formAdd.checkOneways"
                :key="index"
                style="text-align:center"
              >{{item.realCheckNumber}}</td>
              <td
                :key="index"
                style="text-align:center"
              >{{realCheckNumberTotal}}</td>
            </tr>
            <tr>
              <th>备注</th>
              <td
                v-for="(item,index) in formAdd.checkOneways"
                :key="index"
                style="text-align:center"
              >{{item.remark}}</td>
            </tr>
          </table>
          <div style="min-height: 36px;background: #99a9bf;line-height:36px;margin-top:4px;">单程票压票</div>
          <table border="1" bordercolor="#EEEEEE" width="100%">
            <tr>
              <th>项目</th>
              <th>TVM票箱压票数量</th>
              <th>BOM票箱压票数量</th>
              <th>STM票箱压票数量</th>
              <th style="width: 70px;">合计</th>
            </tr>
            <tr style="display: none">
              <th>SC压票总数1</th>
              <td
                v-for="(item,index) in formAdd.checkOnewayPressures"
                :key="index"
                style="text-align:center"
              >{{item.scCleanNumber}}</td>
            </tr>
            <tr>
              <th>实际压票数量</th>
              <td
                v-for="(item,index) in formAdd.checkOnewayPressures"
                :key="index"
                style="text-align:center"
              >{{item.realCheckNumber}}</td>
              <td
                :key="index"
                style="text-align:center"
              >{{scPressuresNumberTotal}}</td>
            </tr>
            <tr>
              <th>备注</th>
              <td
                v-for="(item,index) in formAdd.checkOnewayPressures"
                :key="index"
                style="text-align:center"
              >{{item.remark}}</td>
            </tr>
          </table>
          <dynamic-crud title="营销车票" :data="datayx" :option="tableOptionViewyx" :button="false"></dynamic-crud>
          <dynamic-crud title="应急纸票" :data="datayj" :option="tableOptionViewyj" :button="false"></dynamic-crud>
          <dynamic-crud title="特殊工作卡" :data="datats" :option="tableOptionViewts" :button="false"></dynamic-crud>
          <dynamic-crud title="认证工作卡" v-if="false" :data="datarz" :option="tableOptionViewrz" :button="false"></dynamic-crud>
          <dynamic-crud title="预制单程票" v-if="false" :data="datayz" :option="tableOptionViewyz" :button="false"></dynamic-crud>


          <div style="min-height: 36px;background:#eee;line-height:36px;margin-top:4px;padding: 5px 10px;">审批信息</div>
          <el-row type="flex" justify="left">
            <el-col :span="6" :offset="3" style="margin-top:10px;">
              <el-form-item label="审批状态">
                <el-select v-model="formAdd.ticketCheck.auditStatus" placeholder="请选择">
                  <el-option
                    v-for="item in auditDic"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <!-- 审批状态：{{this.formAdd.ticketCheck.status}} -->
            </el-col>
          </el-row>
          <el-row type="flex" justify="left">
            <el-col :span="18" :offset="3" style="margin-top:10px;">
              <el-form-item label="审批意见">
                <el-input type="textarea" v-model="formAdd.ticketCheck.abnormalNotictContent"></el-input>
              </el-form-item>
              <!-- 审批意见：{{this.formAdd.ticketCheck.abnormalNotictContent}} -->
            </el-col>
          </el-row>
          <el-row type="flex" justify="left">
            <el-col :span="18" :offset="3" style="margin-top:10px;">
              <el-form-item label="备注">
                <el-input type="textarea" :rows="5" v-model="formAdd.ticketCheck.remark" readonly></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row type="flex" justify="center">
            <el-form-item>
              <el-button type="primary" @click="auditSubmit">保存</el-button>
              <el-button @click="editDialogVisible=false">返回</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </el-dialog>

      <el-dialog
        width="70%"
        :visible.sync="viewDialogVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :fullscreen="viewchangeDialogFlag"
      >
        <div slot="title">
          <div>
            <span class="el-dialog__title">预览</span>
            <div class="avue-crud__dialog__menu">
              <button
                class="el-dialog__headerbtn"
                style="margin-right:20px"
                @click.stop="viewchangeDialog"
              >
                <i class="el-dialog__close el-icon-full-screen"></i>
              </button>
            </div>
            <button type="button" aria-label="Close" class="el-dialog__headerbtn">
              <i class="el-dialog__close el-icon el-icon-close"></i>
            </button>
          </div>
        </div>
        <el-form :model="formAdd" label-width="300px">
          <div style="height: 40px;background: #eee;line-height:40px;padding: 5px 10px;margin:0,auto;width:99%;">单程票盘点</div>
          <table border="1" bordercolor="#EEEEEE" width="100%">
            <tr>
              <th>项目</th>
              <th>车站票务管理室原有单程票</th>
              <th>TVM票箱单程票</th>
              <th>BOM票箱单程票</th>
              <th>AGM票箱单程票</th>
              <th>STM票箱单程票</th>
              <th>TVM废票箱单程票</th>
              <th>BOM废票箱单程票</th>
              <th>AGM废票箱单程票</th>
              <th>STM废票箱单程票</th>
              <th>车票回收箱单程票</th>
              <th style="width: 70px;">合计</th>
            </tr>
            <tr style="display: none">
              <th>SC清点总数</th>

              <td
                v-for="(item,index) in formAdd.checkOneways"
                :key="index"
                style="text-align:center"
              >{{item.scCleanNumber}}</td>
            </tr>
            <tr>
              <th>实际盘点数量</th>
              <td
                v-for="(item,index) in formAdd.checkOneways"
                :key="index"
                style="text-align:center"
              >{{item.realCheckNumber}}</td>
              <td
                :key="index"
                style="text-align:center"
              >{{realCheckNumberTotal}}</td>
            </tr>
            <tr>
              <th>备注</th>
              <td
                v-for="(item,index) in formAdd.checkOneways"
                :key="index"
                style="text-align:center"
              >{{item.remark}}</td>
            </tr>
          </table>
          <div style="height: 40px;background: #eee;line-height:40px;padding: 5px 10px;margin:0,auto;width:99%;">单程票压票</div>
          <table border="1" bordercolor="#EEEEEE" width="100%">
            <tr>
              <th>项目</th>
              <th>TVM票箱压票数量</th>
              <th>BOM票箱压票数量</th>
              <th>STM票箱压票数量</th>
              <th style="width: 70px;">合计</th>
            </tr>
            <tr style="display: none">
              <th>SC压票总数2</th>
              <td
                v-for="(item,index) in formAdd.checkOnewayPressures"
                :key="index"
                style="text-align:center"
              >{{item.scCleanNumber}}</td>
            </tr>
            <tr>
              <th>实际压票数量</th>
              <td
                v-for="(item,index) in formAdd.checkOnewayPressures"
                :key="index"
                style="text-align:center"
              >{{item.realCheckNumber}}</td>
              <td
                :key="index"
                style="text-align:center"
              >{{scPressuresNumberTotal}}</td>
            </tr>
            <tr>
              <th>备注</th>
              <td
                v-for="(item,index) in formAdd.checkOnewayPressures"
                :key="index"
                style="text-align:center"
              >{{item.remark}}</td>
            </tr>
          </table>
          <dynamic-crud title="营销车票" :data="datayx" :option="tableOptionViewyx" :button="false" :total="yxCount"></dynamic-crud>
          <dynamic-crud title="应急纸票" :data="datayj" :option="tableOptionViewyj" :button="false" :total="yjCount"></dynamic-crud>
          <dynamic-crud title="特殊工作卡" :data="datats" :option="tableOptionViewts" :button="false" :total="tsCount"></dynamic-crud>
          <dynamic-crud title="认证工作卡" v-if="false" :data="datarz" :option="tableOptionViewrz" :button="false" :total="rzCount"></dynamic-crud>
          <dynamic-crud title="预制单程票" v-if="false" :data="datayz" :option="tableOptionViewyz" :button="false" :total="yzCount"></dynamic-crud>
          <div style='border:1px solid #eee;margin:0 auto;width:99%;'>
            <div style="height: 40px;background: #eee;line-height:40px;padding: 0px 10px;">备注</div>
            <el-row type="flex" justify="left">
              <el-col :span="18" :offset="3" style="margin-top:10px;">
                <el-input type="textarea" :rows="5" v-model="formAdd.ticketCheck.remark" readonly></el-input>
              </el-col>
            </el-row>
          </div>

          <div v-if="formAdd.ticketCheck.status =='3'">
            <div style='border:1px solid #eee;margin:0 auto;width:99%;'>
              <div style="height: 40px;background: #eee;line-height:40px;padding: 0px 10px;">审批信息</div>
              <el-row type="flex" justify="left">
                <el-col
                  :span="6"
                  :offset="6"
                  style="margin-top:10px;"
                >通知内容：{{this.formAdd.ticketCheck.abnormalNotictContent}}</el-col>
              </el-row>
              <!-- <el-row type="flex">
                <el-col
                  :span="10"
                  :offset="6"
                  style="margin-top:10px;"
                >
                <el-form-item label="审批状态">
                    <el-select v-model="formAdd.ticketCheck.auditStatus" placeholder="请选择" disabled>
                      <el-option
                        v-for="item in auditDic"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
                  </el-form-item>
              </el-col>
              </el-row>            -->
            </div>
            <!-- <div style='border:1px solid #eee;margin:0 auto;width:99%;'>
               <div style="height: 40px;background: #eee;line-height:40px;padding: 0px 10px;">异常原因</div>
               <el-row type="flex" justify="left">
                 <el-col
                   :span="6"
                   :offset="6"
                   style="margin-top:10px;"
                 >异常原因：{{this.formAdd.ticketCheck.abnormalNotictReason}}</el-col>
               </el-row>
             </div>  -->

          </div>
          <el-row type="flex" justify="center" style="margin-top:15px;">
            <el-form-item>
              <el-button @click="viewDialogVisible=false">返回</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </el-dialog>
    </basic-container>
  </div>
</template>

<script>
import baseCrud from '@/mixins/base-crud'
import {
  fetchList,
  getObj,
  addObj,
  putObj,
  delObj,
  delsObj,
  checkObj,
  approvalRejectObj
} from "@/api/subwaystm/swstticketcheck";
import {
  tableOptionAddts,
  tableOptionAddyj,
  tableOptionAddyx,
  tableOptionAddyz,
  tableOptionAddrz,
} from "@/const/crud/subwaystm/swstticket/addandedit/swstticketcheckAdd";
import {
  tableOptionViewts,
  tableOptionViewyj,
  tableOptionViewyx,
  tableOptionViewyz,
  tableOptionViewrz,
} from "@/const/crud/subwaystm/swstticket/view/swstticketcheckView";
import reportMistakeInfoEditor from '@/views/subwayRat/reportMondify/reportMistakeInfo/reportMistakeInfoEditor';
import addReportEditor from "@/views/subwayRat/reportMondify/reportMistakeInfo/Editor.vue";
import { startDate, endDate } from "@/const/crud/subwaystm/swstticketcheckaudit";
import { dateFormat } from "@/util/date";

export default {
  name: "swstticketcheck",
  components: {addReportEditor, reportMistakeInfoEditor},
  mixins: [baseCrud('subwaystm/swstticketcheckaudit')],
  data() {
    return {
      auditDic: [
        {
          value: "1",
          label: "审核通过",
        },
        {
          value: "0",
          label: "未审核",
        },
      ],
      tableData: [],
      searchForm: {
        dates1: [startDate, endDate]
      },
      datats: [],
      datarz: [],
      datayz: [],
      datayj: [],
      datayx: [],

      addDialogVisible: false,
      tableOptionAddts: tableOptionAddts,
      tableOptionAddrz: tableOptionAddrz,
      tableOptionAddyj: tableOptionAddyj,
      tableOptionAddyz: tableOptionAddyz,
      tableOptionAddyx: tableOptionAddyx,
      tableOptionViewts: tableOptionViewts,
      tableOptionViewrz: tableOptionViewrz,
      tableOptionViewyj: tableOptionViewyj,
      tableOptionViewyz: tableOptionViewyz,
      tableOptionViewyx: tableOptionViewyx,
      changeDialogFlag: false,
      editDialogVisible: false,
      editchangeDialogFlag: false,
      viewDialogVisible: false,
      viewchangeDialogFlag: false,
      dateFormat: dateFormat,
      formAdd: {
        ticketCheck: {},
        checkOneways: [],
        checkOnewayPressures: [],
        workCards: [],
        workCardsRz: [],
        checkGeneralsYZ: [],
        checkGeneralsYJ: [],
        checkMarketings: [],
        checkGenerals: [],
      },
      //单程票盘点合计
      realCheckNumberTotal: 0,
      // SC压票合计
      scPressuresNumberTotal: 0,
    };
  },
  created() {
    this.delBatch_btn = this.permissions["swstticketcheck_batch_del"];
    this.submitBatch_btn = this.permissions[
      "stm_swstapplynetworkcheckpassengeraffairs_submitBatch"
      ];
  },
  computed: {
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.swstticketcheck_add, false),
        delBtn: this.vaildData(this.permissions.swstticketcheck_del, false),
        superDelBtn: this.vaildData(this.permissions.swstticketcheck_super_del, false),
        editBtn: this.vaildData(this.permissions.swstticketcheck_edit, false),
        auditBtn: this.vaildData(this.permissions.swstticketcheck_check, false)
      };
    },
    tsCount: function () {
      return this.datats.length;
    },
    rzCount: function () {
      return this.datarz.length;
    },
    yzCount: function () {
      let count = 0;
      for (const item of this.datayz) {
        count += Number(item.ticketNum);
      }
      return count + "";
    },
    yjCount: function () {
      let count = 0;
      for (const item of this.datayj) {
        count += Number(item.ticketNum);
      }
      return count + "";
    },
    yxCount: function () {
      let count = 0;
      for (const item of this.datayx) {
        count += Number(item.ticketNum);
      }
      return count + "";
    },
  },
  methods: {
    refreshChange() {
      this.getList()

    },
    rowStyle({ row, column, rowIndex }) {
      if (row.status == "0") {
        return {
          backgroundColor: "#eee",
          color: "red",
        };
      }
    },
    search() {
      this.listLoading = true;
      this.page.size = this.page.pageSize;
      this.page.current = this.page.currentPage;
      Object.assign(this.searchForm, this.page);
      this.searchForm.userCode = this.$store.getters.userInfo.userCode;
      this.searchForm.reportType = 1;
      //日期范围
      let dates1 = this.searchForm.dates1;
      if (dates1 != null && dates1 != '') {
        this.searchForm.startdate = dates1[0].substr(0, 10);
        this.searchForm.enddate = dates1[1].substr(0, 10);
      }
      fetchList(this.searchForm).then((res) => {
        this.tableData = res.data.data.records;
        this.listLoading = false;
        this.page.total = res.data.data.total;
      });
    },
    handleFilter(params, done) {
      // Object.assign(this.searchForm, params);
      this.getList()
      done()
    },
    auditSubmit(){
      checkObj(this.formAdd.ticketCheck).then((response)=>{
        this.$message.success("审批成功");
        this.editDialogVisible=false
        this.getList(this.page)
      })
    },
    delBatch: function () {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.error("请勾选数据");
        return false;
      }
      let ids = [];
      for (const id of this.$refs.crud.tableSelect) {
        ids.push(id.id);
      }
      delsObj(ids)
        .then((data) => {
          this.$message.success("删除成功");
          this.getList(this.page);
          done();
        })
        .catch(() => {
          loading();
        });
    },
    selectionChange(list) {
      this.multipleSelectionRows = list;
      this.multipleSelectionKeys = [];
      for (let i = 0; i < list.length; i++) {
        this.multipleSelectionKeys.push(list[i].id);
      }
    },
    getList() {
      const params = this.$route.query;
      console.log(JSON.stringify(params))
      const p = {};
      if (Object.keys(params).length) {
        p.lineCode = params.lineCode;
        p.stationCode = params.stationCode;
        p.dates1 = [params.reprotTime, params.reprotTime]
        p.selType = '1'; //报表跳转查询
      }
      this.listLoading = true;
      this.page.size = this.page.pageSize;
      this.page.current = this.page.currentPage;
      Object.assign(this.searchForm, this.page);
      this.searchForm.userCode = this.$store.getters.userInfo.userCode;
      fetchList(Object.keys(params).length ? p : this.searchForm).then((response) => {
        this.tableData = response.data.data.records;
        this.listLoading = false;
        this.page.total = response.data.data.total;
      });
    },
    myAdd() {
      this.formAdd.checkOneways = [
        {
          ticketType: "0",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
        {
          ticketType: "1",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
        {
          ticketType: "2",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
        {
          ticketType: "3",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
        {
          ticketType: "4",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
        {
          ticketType: "5",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
        {
          ticketType: "6",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
        {
          ticketType: "7",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
        {
          ticketType: "8",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
        {
          ticketType: "9",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
      ];
      this.formAdd.checkOnewayPressures = [
        {
          ticketType: "0",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
        {
          ticketType: "1",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
        {
          ticketType: "2",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: "",
        },
      ];
      this.datayz = [];
      this.datayj = [];
      this.datayx = [];
      this.datats = [];
      this.datarz = [];
      this.addDialogVisible = true;
    },
    myEdit: function (row) {
      getObj(row.id)
        .then((response) => {
          let res = response.data.data;
          let workCardsMy = [];
          let workCardsRzMy = [];
          for (const item of res.workCards) {
            if (item.ticketType == "0") {
              workCardsMy.push(item);
            } else {
              workCardsRzMy.push(item);
            }
          }
          this.datats = workCardsMy;
          this.datarz = workCardsRzMy;
          let checkGeneralsYZMy = [];
          let checkGeneralsYJMy = [];
          for (const item of res.checkGenerals) {
            if (item.ticketType == "0") {
              checkGeneralsYZMy.push(item);
            } else {
              checkGeneralsYJMy.push(item);
            }
          }
          this.datayz = checkGeneralsYZMy;
          this.datayj = checkGeneralsYJMy;
          this.datayx = res.checkMarketings;
          this.formAdd.checkOnewayPressures = res.checkOnewayPressures;
          this.formAdd.checkOneways = res.checkOneways;
          this.formAdd.ticketCheck = res.ticketCheck;
          this.formAdd.ticketCheck.status = '2'
          this.realCheckNumberTotal = 0
          this.scPressuresNumberTotal = 0
        })
        .then(() => {
          this.realCheckNumberChange();
          this.scPressuresNumberChange();
          this.editDialogVisible = true;
        });
    },
    myView: function (row) {
      getObj(row.id)
        .then((response) => {
          let res = response.data.data;
          let workCardsMy = [];
          let workCardsRzMy = [];
          for (const item of res.workCards) {
            if (item.ticketType == "0") {
              workCardsMy.push(item);
            } else {
              workCardsRzMy.push(item);
            }
          }
          this.datats = workCardsMy;
          this.datarz = workCardsRzMy;
          let checkGeneralsYZMy = [];
          let checkGeneralsYJMy = [];
          for (const item of res.checkGenerals) {
            if (item.ticketType == "0") {
              checkGeneralsYZMy.push(item);
            } else {
              checkGeneralsYJMy.push(item);
            }
          }
          this.datayz = checkGeneralsYZMy;
          this.datayj = checkGeneralsYJMy;
          this.datayx = res.checkMarketings;
          this.formAdd.checkOnewayPressures = res.checkOnewayPressures;
          this.formAdd.checkOneways = res.checkOneways;
          this.formAdd.ticketCheck = res.ticketCheck;
          this.realCheckNumberTotal = 0;
          this.scPressuresNumberTotal = 0;
        })
        .then(() => {
          this.realCheckNumberChange();
          this.scPressuresNumberChange();
          this.viewDialogVisible = true;
        });
    },
    // 更新实际盘点数量合计值
    realCheckNumberChange(index) {
      this.realCheckNumberTotal = this.formAdd.checkOneways.reduce((acc, item) => acc + (parseFloat(item.realCheckNumber) || 0), 0);
    },
    // 更新SC压票总数合计值
    scPressuresNumberChange(index) {
      this.scPressuresNumberTotal = this.formAdd.checkOnewayPressures.reduce((acc, item) => acc + (parseFloat(item.realCheckNumber) || 0), 0);
    },
    //驳回
    rejectBatch() {
      var tableSelect = this.$refs.crud.tableSelect;
      if (tableSelect.length == 0) {
        this.$message.info("请选择要驳回的记录");
        return;
      }
      for (const item of tableSelect) {
        if (item.status != 1 || item.auditStatus != 0) {
          this.$message.error("请选择已提交且未审核的数据！");
          this.$refs.crud.toggleSelection();
          return false;
        }
      }
      var ids = tableSelect.map(row => row.id);
      const params = {
        ids: ids.join(","),
        status: "0"
      };
      approvalRejectObj(params).then(response => {
        this.$message.success("驳回成功");
        this.getList(this.page);
      });
    },
    async addReportData() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.error("请选择数据");
        return false;
      }
      if (this.$refs.crud.tableSelect.length != 1) {
        this.$message.error("只能选择一条数据");
        return false;
      }
      let res = false;
      let ress = false;
      for (const table of this.$refs.crud.tableSelect) {
        if (table.status != "1") {
          this.$message.error("请选择已提交的数据");
          return false;
        } else {
          if (table.isAddReprotError == "1") {
            res = await this.$confirm('该数据已加入报表差错，是否重新加入？', '提示', {
              confirmButtonText: '是',
              cancelButtonText: '否',
              type: 'warning'
            });
            if (!res) {
              return;
            } else {
              ress = true;
            }
          }
        }
      }
      if (res == false) {
        ress = await this.$confirm("是否加入报表差错", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        });
      }
      if (!ress) {
        return;
      }
      this.selectKeys = this.$refs.crud.tableSelect;
      let param = {
        dialogTitle: "加入报表差错",
        diffAmountId: this.selectKeys[0].id,
        dataSourceTable: "sw_st_stock",
        lineCode: this.selectKeys[0].lineCode,
        stationCode: this.selectKeys[0].stationCode,
        reprotTime: this.selectKeys[0].checkTime,
        reportNameId: 14,
        settleBeginTime: this.selectKeys[0].checkTime,
        settleEndTime: this.selectKeys[0].checkTime,
	userCodes:this.selectKeys[0].conductorJobNo,
	dutyStationLeaderCode: this.selectKeys[0].workPersonJobNo, 
	dutyStationLeaderName: this.selectKeys[0].workPersonName, 
        showType: 3,
        dataSource: 14
      };
      this.$refs.addReportEditor.others_report_add_call(param);
    },
    //高级删除操作
    myDelete: function (row) {
      this.$confirm("确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        delObj(row.id)
          .then((data) => {
            this.$message.success("删除成功");
            this.getList(this.page);
            done();
          })
          .catch(() => {
            loading();
          });
      });
    },

    editAdd: function (done) {
      this.formAdd.workCards = this.datats.concat(this.datarz);
      this.formAdd.checkGenerals = this.datayz.concat(this.datayj);
      this.formAdd.checkMarketings = this.datayx;
      console.log(this.formAdd);
      putObj(this.formAdd)
        .then((data) => {
          this.$message.success("修改成功");
          this.editDialogVisible = false;
          this.getList(this.page);
          done();
        })
        .catch(() => {
        });
    },
    submitAdd: function (done) {
      this.formAdd.workCards = this.datats.concat(this.datarz);
      this.formAdd.checkGenerals = this.datayz.concat(this.datayj);
      this.formAdd.checkMarketings = this.datayx;
      this.formAdd.checkOnewayPressures = this.formAdd.checkOnewayPressures;
      this.formAdd.checkOneways = this.formAdd.checkOneways;
      this.formAdd.ticketCheck.checkTime = dateFormat(new Date());

      console.log(this.formAdd);
      addObj(this.formAdd)
        .then((data) => {
          this.$message.success("添加成功");
          this.addDialogVisible = false;
          this.getList(this.page);
          done();
        })
        .catch(() => {
        });
    },
    changeDialog: function () {
      if (this.changeDialogFlag) {
        this.changeDialogFlag = false;
      } else {
        this.changeDialogFlag = true;
      }
    },
    editchangeDialog: function () {
      if (this.editchangeDialogFlag) {
        this.editchangeDialogFlag = false;
      } else {
        this.editchangeDialogFlag = true;
      }
    },
    viewchangeDialog: function () {
      if (this.viewchangeDialogFlag) {
        this.viewchangeDialogFlag = false;
      } else {
        this.viewchangeDialogFlag = true;
      }
    }
  }
}
</script>

<style>
.el-col-offset-6 {
  margin-left: 2%;
}
</style>
